package com.yc.bank.dao;

import com.yc.bank.entity.Oprecord;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;

import javax.annotation.Resource;
import java.util.List;

@Repository
public class OprecordDao {

    @Resource
    JdbcTemplate jdbcTemplate;

    public void insert(Oprecord oprecord) {
        String sql = "insert into bank_oprecord values" +
                " (default,?,?,?,now(),?)";
        jdbcTemplate.update(sql,
                oprecord.getAid(),
                oprecord.getOpmoney(),
                oprecord.getCharge(),
                oprecord.getRemark());
    }

    public List<Oprecord> selectByAid(String aid) {
        String sql = "select * from bank_oprecord where aid=?";
        return jdbcTemplate.query(sql
                , new BeanPropertyRowMapper<>(Oprecord.class)
                , aid);
    }
}
